<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>水平垂直居中-浮动方法</title>
        <style type="text/css">
            .container{
                background-color:#338BC7;
                width:270px;
                height:150px;
            }
            </style>
    </head>
    <body>
        <div class="container">
            <p>Centered In The Middle Of The Page With jQuery</p>
        </div>
        <script src="//cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $(window).resize(function(){
                    $('.container').css({
                        position:'absolute',
                        left: ($(window).width() - $('.container').outerWidth())/2,
                        top: ($(window).height() - $('.container').outerHeight())/2
                    });
                });
                // 最初运行函数
                $(window).resize();
            });
        </script>
    </body>
</html>